package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.*;
import com.sky.entity.Category;
import com.sky.entity.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import com.sky.service.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/page")
    @ApiOperation("分页查询分类")
    public Result<PageResult> pageFind(CategoryPageQueryDTO queryDTO) {
        log.info("分页查询分类，参数：{}", queryDTO);
        PageResult result =categoryService.pageFind(queryDTO);
        return Result.success(result);
    }
    @PostMapping("/status/{status}")
    @ApiOperation("改变菜品状态")
    public Result<String> updateStatus(@RequestParam(name = "id") Long id,@PathVariable("status") Integer status) {
        log.info("禁用/启用菜品,菜品id：{}，当前菜品状态，{}", id,status);
        categoryService.changeStatus(id,status);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品分类信息")
    public Result<Category> get(@PathVariable("id") Long id) {
        log.info("根据Id查询菜品信息，id：{}",id);
        Category category= categoryService.findById(id);
        return Result.success(category);
    }
    @PutMapping()
    @ApiOperation("编辑菜品信息")
    public Result<String> update(@RequestBody CategoryDTO categoryDTO) {
        log.info("修改菜品信息,菜品信息：{}", categoryDTO);
        categoryService.updateinfo(categoryDTO);
        return Result.success();
    }
    @PostMapping()
    @ApiOperation("新增分类")
    public Result<String> insert(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增分类,分类信息{}", categoryDTO);
        categoryService.add(categoryDTO);
        return Result.success();
    }
    @DeleteMapping()
    @ApiOperation("根据id删除分类")
    public Result<String> delete(Long id) {
        log.info("根据id删除分类,分类id：{}", id);
        categoryService.delById(id);
        return Result.success();
    }
    @GetMapping("/list")
    @ApiOperation("根据type获取分类类列表")
    public Result<List<Category>> list(Integer type) {
        List<Category> list=categoryService.listGetByType(type);
        return Result.success(list);
    }
}
